package com.white.commonlib.engine;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;

import com.white.commonlib.adapter.recycle.LinearLayoutDivider;

/**
 * Created by ytf on 2017/9/10 010.
 * Description:
 */

public class DefaultRecycleViewSetter
{
    private RecyclerView rl;
    private RecyclerView.Adapter ad;
    private int direction;
    private int dividerWidth;
    private int dividerColor;

    private Context mContext;

    public DefaultRecycleViewSetter(Context mContext, RecyclerView v, RecyclerView.Adapter adapter)
    {
        rl = v;
        this.mContext = mContext;
        ad = adapter;
        dividerWidth = 1;
        dividerColor  = 0xFFEDEDED;
        direction = 0;
    }

    public DefaultRecycleViewSetter setDiverStyle(int c, int width)
    {
        dividerColor = c;
        dividerWidth = width;
        return this;
    }

    /****
     *
     * @param d 0垂直   1 水平
     * @return
     */
    public DefaultRecycleViewSetter setDirection(int d)
    {
        direction = d;
        return this;
    }

    RecyclerView.LayoutManager manager;
    public DefaultRecycleViewSetter setManager(RecyclerView.LayoutManager m)
    {
        manager = m;
        return this;
    }

    public void set()
    {
        if(manager == null)
            manager = new LinearLayoutManager(mContext , direction == 0 ?
                    OrientationHelper.VERTICAL : OrientationHelper.HORIZONTAL, false);
        rl.setLayoutManager(manager);
        rl.setAdapter(ad);
        LinearLayoutDivider d = new LinearLayoutDivider(mContext, LinearLayoutDivider.LINEAR_V);
        d.setDividerStyle(dividerWidth, dividerColor);
        rl.addItemDecoration(d);
    }
}
